//
//  DPMeWalletHeaderView.swift
//  DoctorEPlus
//
//  Created by 王林波 on 2021/3/8.
//

import UIKit

class DPMeWalletHeaderView: UIView {

    var headerDidSelectIndexBlock:((Int) -> Void)?
    
    @IBOutlet weak var money_label: UILabel!
    
    
    @IBOutlet weak var rechargeBtn: UIButton!
    
    
    
    static func loadFromXib() -> DPMeWalletHeaderView {
        let array = Bundle.main.loadNibNamed("DPMeWalletHeaderView", owner: nil, options: nil)
        let view = array![0] as! DPMeWalletHeaderView
        return view
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        self.rechargeBtn.backgroundColor = UIColor.white.withAlphaComponent(0.15)
        
        self.rechargeBtn.addLayerCorner(12, 0.5, .white)
    }

    
    @IBAction func rechargeBtnAct(_ sender: UIButton) {
        self.headerDidSelectIndexBlock?(0)
        
    }
    
    @IBAction func seeAllAct(_ sender: UIButton) {
        self.headerDidSelectIndexBlock?(1)
    }
    
    
    static var headerHeight: CGFloat {
        get {
            return CGFloat(167).radius+95
        }
    }
    
}



class DPMeWalletOutInSecView: UIView {
    @IBOutlet weak var date_label: UILabel!
    
    @IBOutlet weak var out_label: UILabel!
    
    @IBOutlet weak var in_label: UILabel!
    
    
    
    static func loadFromXib() -> DPMeWalletOutInSecView {
        let array = Bundle.main.loadNibNamed("DPMeWalletHeaderView", owner: nil, options: nil)
        let view = array![1] as! DPMeWalletOutInSecView
        return view
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
       
    }
    
    static var height: CGFloat {
        get {
            return 40
        }
    }
}




class DPWalletWithDrawBottomView: UIView {
    
    var bottomViewDidSelectIndexBlock:((Int) -> Void)?

    
    @IBOutlet weak var confirmBtn: UIButton!
    
    @IBOutlet weak var bottomConstant: NSLayoutConstraint!
    
    static func loadFromXib() -> DPWalletWithDrawBottomView {
        let array = Bundle.main.loadNibNamed("DPMeWalletHeaderView", owner: nil, options: nil)
        let view = array![2] as! DPWalletWithDrawBottomView
        return view
    }
 
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        self.bottomConstant.constant = UIScreen.safeBottomHeight+30
        self.confirmBtn.addLayerCorner(5, 0, .white)
       
    }
    @IBAction func confirmAct(_ sender: UIButton) {
        self.bottomViewDidSelectIndexBlock?(0)
    }
    
    
    @IBAction func serviceAct(_ sender: UIButton) {
        self.bottomViewDidSelectIndexBlock?(1)
    }
    
}




// 账单详情
class DPWalletFlowDetailHeaderView: UIView {
    
    @IBOutlet weak var title_label: UILabel!
    
    @IBOutlet weak var money_label: UILabel!
    
    static func loadFromXib() -> DPWalletFlowDetailHeaderView {
        let array = Bundle.main.loadNibNamed("DPMeWalletHeaderView", owner: nil, options: nil)
        let view = array![3] as! DPWalletFlowDetailHeaderView
        return view
    }
 
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
       
    }
    
    var model: DPWalletFlowItemModel! {
        didSet {
            self.title_label.text = model.title
            
            if model.type == 1 { // 收入
                self.money_label.text = "+"+model.amount
            }else {
                self.money_label.text = "-"+model.amount
            }
        }
    }
    
    
    static var height: CGFloat {
        get {
            return 200
        }
    }
}

class DPWalletFlowDetailFooterView: UIView {
    @IBOutlet weak var bottomConstant: NSLayoutConstraint!

    static func loadFromXib() -> DPWalletFlowDetailFooterView {
        let array = Bundle.main.loadNibNamed("DPMeWalletHeaderView", owner: nil, options: nil)
        let view = array![4] as! DPWalletFlowDetailFooterView
        return view
    }
 
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        self.bottomConstant.constant = UIScreen.safeBottomHeight+30
       
       
    }
    
    // 联系客服
    @IBAction func connectServiceAct(_ sender: UIButton) {
        
    }
}



class DPWalletAllBillHeaderView: UIView {
    
    var didChangeIndexBlock:((Int) -> Void)?
    
    
    @IBOutlet weak var allBillBtn: UIButton!
    
    @IBOutlet weak var inBtn: UIButton!
    
    @IBOutlet weak var outBtn: UIButton!
    
    fileprivate var remarkBtn: UIButton!
    
    
    static func loadFromXib() -> DPWalletAllBillHeaderView {
        let array = Bundle.main.loadNibNamed("DPMeWalletHeaderView", owner: nil, options: nil)
        let view = array![5] as! DPWalletAllBillHeaderView
        return view
    }
 
    var currentIndex: Int = 0 {
        didSet {
            self.remarkBtn.isSelected = false
            self.remarkBtn = (self.viewWithTag(currentIndex+100) as! UIButton)
            self.remarkBtn.isSelected = true
        }
    }
    
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        self.remarkBtn = allBillBtn
       
    }
    
    @IBAction func billAct(_ sender: UIButton) {
        if self.remarkBtn == sender {
            return
        }
        
        self.remarkBtn.isSelected = false
        sender.isSelected = true
        self.remarkBtn = sender
        
        self.didChangeIndexBlock?(sender.tag - 100)
    }
    
    
    
}
